//
//  UserPresenter.swift
//  AppArchitectureSwift
//
//  Created by 胡锦涛 on 2019/2/20.
//  Copyright © 2019 胡锦涛. All rights reserved.
//

import UIKit

protocol UserViewDelegate : NSObjectProtocol{
    
    /// 开始加载
    func startLoading()
    
    /// 完成加载
    func finishLoading()
    
    ///用户界面的数据
    func setUsers(_ userViewData:[User])
    
    ///数据是空的时候显示
    func setEmptyUsers()
    
}

class UserPresenter: NSObject {
    
    ///User-Delegate
    weak var delegate : UserViewDelegate?
    
    func getUsers() {
        User.getUsers { [weak self](users) in
            self?.delegate?.finishLoading()
            let hasUser:Bool = !users.isEmpty && users.count > 0
            if !hasUser {
                self?.delegate?.setEmptyUsers()
            }else {
                //将数据传出到控制器
                self?.delegate?.setUsers(users)
            }
        }
    }
    
    
}
